#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: shielding_task_from_cancellation.py
@date: 2025-07-26 19:34
@author: Falling Snow
@desc: 设置超时提醒, 但不取消task
"""
import asyncio

from util import delay


async def main():
    task = asyncio.create_task(delay(10))
    try:
        res = await asyncio.wait_for(asyncio.shield(task), 5)
        print(res)
    except asyncio.exceptions.TimeoutError:
        print("task已经运行超过5秒了, 他很快将要完成")
        # 这里的await对象和上面的await不一样
        res = await task
        print(res)


if __name__ == '__main__':
    asyncio.run(main())
